﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Configuration;
using SIPO.Library.DomainObject.Administration.UserManagement;
using SIPO.Web.Support;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;

using System.Web.SessionState;

namespace SIPO.Web.Lists.Transaction
{
    public partial class recLoadReconlist : BasePage, IRequiresSessionState
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack) {
                recBankAccountRepo bankRepo = new recBankAccountRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                List<recBankAccount> banks = bankRepo.GetList();

                ddlBank.Items.Clear();
                banks.ForEach(delegate(recBankAccount bank)
                {
                    ddlBank.Items.Add(new ListItem(bank.BankCode + " - " + bank.BankName, bank.BankID.ToString()));
                });
                ddlBank.Items.Insert(0, new ListItem("-- pilih bank --", string.Empty));

                Session["loadRekonDetailID"] = null;
                
                GetPrivilege();
            }

        }

        private void GetPrivilege()
        {
            Membership membership = new Membership(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);

            List<recAccessRights.AccessRights> accessRights = membership.GetAccessRights(base.UserID, base.MenuID);

            accessRights.ForEach(delegate(recAccessRights.AccessRights access)
            {
                switch (access)
                {
                    case (recAccessRights.AccessRights.View):
                        ClientScript.RegisterStartupScript(typeof(Page), "view", "$('#btnAdd').hide();$('#btnEdit').hide();$('#btnDelete').hide();$('#btnLoadRekKoran').hide();$('#btnUpdate').hide();", true); //$('#btnAutoRekonsiliasi').hide();
                        break;
                    case (recAccessRights.AccessRights.Add):
                        ClientScript.RegisterStartupScript(typeof(Page), "add", "$('#btnAdd').show();", true);
                        break;
                    case (recAccessRights.AccessRights.Edit):
                        ClientScript.RegisterStartupScript(typeof(Page), "edit", "$('#btnEdit').show();", true);
                        break;
                    case (recAccessRights.AccessRights.Delete):
                        ClientScript.RegisterStartupScript(typeof(Page), "delete", "$('#btnDelete').show();", true);
                        break;
                    case (recAccessRights.AccessRights.Review):
                        ClientScript.RegisterStartupScript(typeof(Page), "loadrekkoran", "$('#btnLoadRekKoran').show();", true);
                        break;
                    //case (recAccessRights.AccessRights.Approve):
                    //    ClientScript.RegisterStartupScript(typeof(Page), "autorekonsiliasi", "$('#btnAutoRekonsiliasi').show();", true);
                    //    break;
                    case (recAccessRights.AccessRights.Open):
                        ClientScript.RegisterStartupScript(typeof(Page), "updatepembayaran", "$('#btnUpdate').show();", true);
                        break;
                    case (recAccessRights.AccessRights.NoAccess):
                        var url = Helper.GetAppVirtualPath(Page);
                        //ClientScript.RegisterStartupScript(typeof(Page), "noAccess", "alert('Anda tidak mempunyai hak akses ke halaman ini!'); window.location = '" + url + "'", true);
                        break;
                }
            });

        }
    }
}